class Admin::GpsController < Admin::ApplicationController
  before_filter :base_breadcrumb

  def index
    # 获取所有管理者下的员工信息
    @users = User.where(area:current_user.area,group:current_user.group)
    # 查找对应的用户(有参数和无参数)
    @user =  params[:user_id].present? ? User.find_by_id(params[:user_id]) : current_user
    # 用户对应订单
    @orders = initialize_grid(Order.where(user_id:@user.id), page: params[:page],per_page: 5, order: :created_at, order_direction: :desc)
  end

  def show
    # 获取所有管理者下的员工信息
    @users = User.where(area:current_user.area,group:current_user.group)
    # 查找对应的用户(有参数和无参数)
    @user =  params[:user_id].present? ? User.find_by_id(params[:user_id]) : current_user
    # 用户对应订单
    @orders = initialize_grid(Order.where(user_id:@user.id), page: params[:page],per_page: 5, order: :created_at, order_direction: :desc)
    # 订单详情
    if params[:id].present?
      @order = get_order(params[:id])[:order]
    else
      @order = Order.where(user_id:@user.id).first
    end

  end

  def follow
    # 获取所有管理者下的员工信息
    @users = User.where(area:current_user.area,group:current_user.group)
    # 查找对应的用户(有参数和无参数)
    @user =  params[:user_id].present? ? User.find_by_id(params[:user_id]) : current_user
    # 用户对应订单
    @orders = initialize_grid(Order.where(user_id:@user.id), page: params[:page],per_page: 5, order: :created_at, order_direction: :desc)
  end

  def get_order(id)
    # 查找到固定id的订单
    @order = Order.find_by_id(id)
    if @order.present?
      return {order:@order}
    else
      return {message:'error'}
    end
  end


  private
  def base_breadcrumb
    add_breadcrumb "售后服务订单", admin_gps_path
  end
end